// const mysql=require('mysql');
// const connection = mysql.createConnection({
//     host:'127.0.0.1',
//     user:'root',
//     password:'root',
//     database:'albx_38'
// })
const {connection}=require('./sqlhelper')
module.exports={
    getAllCategories(callback){
        let sql = `SELECT * FROM categories`;
        connection.query(sql,(err, results)=>{
            err&&console.log(err);
            callback(results)
        })
    },
    addNewCategoy(name, slug, classname,callback){
        let sql=`INSERT into categories SET slug='${slug}',\`name\`='${name}',classname='${classname}'`
        connection.query(sql,(err,result)=>{
            err&&console.log(err);
            callback(result);
        })
    },
    getCategoyById(id,callback){
        let sql = `SELECT * FROM categories WHERE id='${id}'`;
        connection.query(sql,(err,result)=>{
            err&&console.log(err);
            callback(result[0]);
        })
    },
    deleteCategoiesById(id,callback){
        let sql = `UPDATE categories set isDelete='1' WHERE id='${id}'`
        connection.query(sql,(err,result)=>{
            err&&console.log(err);
            callback(result);
        })
    },
    regainCategoiesById(id, callback) {
        let sql = `UPDATE categories set isDelete='1' WHERE id='${id}'`
        connection.query(sql, (err, result) => {
            err && console.log(err);
            callback(result);
        })
    },
    getCategoryByid(id,callback){
        let sql = `SELECT * FROM categories WHERE id='${id}'`
        connection.query(sql,(err,result)=>{
            err && console.log(err);
            callback(result[0]);
        })
    },
    editCategoryById(name,slug,classname,id,callback){
        let sql=`UPDATE categories SET \`name\`='${name}',slug='${slug}',classname='${classname}' WHERE id='${id}'`;
        connection.query(sql,(err,result)=>{
            err && console.log(err);
            callback(result);
        })
    },
    getNavigatorList(callback){
        let sql = `SELECT * FROM categories WHERE isDelete = 0 AND id != 1`
        connection.query(sql,(err,result)=>{
            err && console.log(err);
            callback(result);
        })
    }
}